<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>我的任务</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
    <div th:replace="~{fragments/header :: header}"></div>
    
    <div class="container mt-4">
        <div class="d-flex justify-content-between align-items-center mb-4">
            <h2>我的任务</h2>
            <a th:href="@{/employer/tasks/publish}" class="btn btn-primary">发布新任务</a>
        </div>
        
        <!-- 搜索表单 -->
        <div class="card mb-4">
            <div class="card-body">
                <form th:action="@{/employer/tasks/search}" method="get" class="row g-3">
                    <div class="col-md-5">
                        <label for="title" class="form-label">按标题搜索</label>
                        <input type="text" class="form-control" id="title" name="title" placeholder="输入任务标题" th:value="${searchTitle}">
                    </div>
                    <div class="col-md-5">
                        <label for="status" class="form-label">按状态筛选</label>
                        <select class="form-control" id="status" name="status">
                            <option value="" th:selected="${searchStatus == null or searchStatus == ''}">全部状态</option>
                            <option value="open" th:selected="${searchStatus == 'open'}">待承接</option>
                            <option value="in_progress" th:selected="${searchStatus == 'in_progress'}">进行中</option>
                            <option value="completed" th:selected="${searchStatus == 'completed'}">已完成</option>
                            <option value="closed" th:selected="${searchStatus == 'closed'}">已关闭</option>
                        </select>
                    </div>
                    <div class="col-md-2 d-flex align-items-end">
                        <button type="submit" class="btn btn-primary me-2">搜索</button>
                        <a th:href="@{/employer/tasks}" class="btn btn-secondary">重置</a>
                    </div>
                </form>
            </div>
        </div>
        
        <!-- 任务列表 -->
        <div class="row">
            <div class="col-12">
                <div th:if="${tasks == null or tasks.empty}" class="alert alert-info">
                    暂无任务
                </div>
                
                <div th:if="${tasks != null and !tasks.empty}">
                    <div class="table-responsive">
                        <table class="table table-striped table-hover">
                            <thead>
                                <tr>
                                    <th>任务编号</th>
                                    <th>任务标题</th>
                                    <th>预算</th>
                                    <th>状态</th>
                                    <th>发布时间</th>
                                    <th>操作</th>
                                </tr>
                            </thead>
                            <tbody>
                                <tr th:each="task : ${tasks}">
                                    <td th:text="${task.taskId}">任务编号</td>
                                    <td th:text="${task.title}">任务标题</td>
                                    <td th:text="${'￥' + #numbers.formatDecimal(task.budget, 1, 2)}">预算</td>
                                    <td>
                                        <span th:if="${task.taskStatus == 'open'}" class="badge bg-primary">待承接</span>
                                        <span th:if="${task.taskStatus == 'in_progress'}" class="badge bg-warning">进行中</span>
                                        <span th:if="${task.taskStatus == 'completed'}" class="badge bg-success">已完成</span>
                                        <span th:if="${task.taskStatus == 'closed'}" class="badge bg-secondary">已关闭</span>
                                    </td>
                                    <td th:text="${#temporals.format(task.publishDate, 'yyyy-MM-dd HH:mm')}">发布时间</td>
                                    <td>
                                        <a th:href="@{/employer/tasks/{taskId}(taskId=${task.taskId})}" class="btn btn-sm btn-primary">查看</a>
                                        <a th:href="@{/employer/tasks/{taskId}/edit(taskId=${task.taskId})}" class="btn btn-sm btn-warning">编辑</a>
                                        <a th:href="@{/task-reviews/create(taskId=${task.taskId})}" class="btn btn-sm btn-info" th:if="${task.taskStatus == 'completed'}">评价</a>
                                        <form th:action="@{/employer/tasks/{taskId}/delete(taskId=${task.taskId})}" method="post" style="display: inline;">
                                            <button type="submit" class="btn btn-sm btn-danger" 
                                                    onclick="return confirm('确定要删除这个任务吗？')">删除</button>
                                        </form>
                                    </td>
                                </tr>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
    
    <div th:replace="~{fragments/footer :: footer}"></div>
</body>
</html>